<title>节点信息</title>
<form class="layui-form" action="" lay-filter="node-config-form-element">
    <div class="layui-card" style="padding-top: 20px;font-weight:bold;">
        <div class="layui-row">
            <div class="layui-form-item layui-col-md6" style="margin-left: 23%;">
                <label class="layui-form-label">流程名称</label>
                <div class="layui-input-line">
                    <script type="text/html" lay-url="{{layui.setter.APIURL.apiurl}}flowbusinessconfig/getBusinessList?timestamp=(new Date()).valueOf()"
                            lay-done="layui.data.done(d);" template>
                        <div class="layui-input-block">
                            <select name="flowCode" lay-verify="required" lay-filter="flowCode-element">
                                <option value="" selected=""></option>
                                {{# layui.each(d.data, function(index, item){}}
                                <option value="{{ item.flowCode }}">{{ item.flowName }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </script>
                    <script>
                        layui.data.done = function (d) {
                            layui.use(['form'], function () {
                                var form = layui.form;
                                form.render(null, 'flowCode-element'); //渲染该模板下的动态表单
                                form.render('select'); //渲染该模板下的动态表单
                            });
                        };
                    </script>
                </div>
            </div>
            <div class="layui-col-md2" style="color: red;margin-top: 1%;padding-left: 1%;">*</div>
        </div>
        <div class="layui-row">
            <div class="layui-form-item layui-col-md6" style="margin-left: 23%;">
                <label class="layui-form-label">节点编码</label>
                <div class="layui-input-block">
                    <input type="hidden" name="id" id="id"/>
                    <input type="text" name="nodeCode" id="nodeCode" lay-verify="required" placeholder="请选择节点编码"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-md2" style="color: red;margin-top: 1%;padding-left: 1%;">*</div>
        </div>
        <div class="layui-row">
            <div class="layui-form-item layui-col-md6" style="margin-left: 23%;">
                <label class="layui-form-label">节点名称</label>
                <div class="layui-input-block">
                    <input type="text" name="nodeNameCg" id="nodeNameCg" lay-verify="required" placeholder="请输入节点名称"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-md2" style="color: red;margin-top: 1%;padding-left: 1%;">*</div>
        </div>
        <div class="layui-row" style="text-align: center">
            <div class="layui-form-item layui-col-md8">
                <button lay-submit lay-filter="node-config-form-element"
                        class="layui-btn layui-btn-normal layui-btn-lg">保存
                </button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-lg" lay-filter="user-form-closed"
                        id="nodeConfigClosed">关闭本页
                </button>
            </div>
        </div>
    </div>
</form>
<script>
    var token = layui.data('x_auth_token').x_auth_token
    layui.use(['admin', 'form', 'upload', 'dtree', 'layer'], function () {
        var $ = layui.$;
        var form = layui.form;
        var admin = layui.admin;
        var upload = layui.upload;
        var router = layui.router();
        var dtree = layui.dtree;
        var layer = layui.layer;

        if (router.search.nodeId) { // 若携带id则为编辑模式
            admin.req({
                url: layui.setter.APIURL.apiurl + 'nodeConfig/getNodeConfig?nodeId=' + router.search.nodeId + '&timestamp=' + new Date().valueOf(),
                done: function (res) {
                    if (res.code == 0) {
                        form.val('node-config-form-element', {
                            'id': res.data.id,
                            'flowCode': res.data.flowCode,
                            'nodeCode': res.data.nodeCode,
                            'nodeNameCg': res.data.nodeName
                        });
                        return false;
                    }
                }
            });
        }

        // 保存监听
        form.on('submit(node-config-form-element)', function (data) {
            var field = data.field;
            var strUrls = 'nodeConfig/saveNodeConfig?timestamp=' + new Date().valueOf();
            if (field.id) {
                strUrls = 'nodeConfig/editNodeConfig?timestamp=' + new Date().valueOf();
            }
            admin.req({
                url: layui.setter.APIURL.apiurl + strUrls //实际使用请改成服务端真实接口
                , type: 'POST'
                , data: JSON.stringify(field),
                done: function (res) {
                    if (res.code != 0) {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    } else {
                        layer.msg(res.msg, {icon: 1});
                        var interval = setInterval(function () {
                            layui.admin.events.closeThisTabs();
                            clearInterval(interval);
                        }, 3000);
                    }
                }
            });
            return false
        });

        $('#nodeConfigClosed').click(function () {
            layui.admin.events.closeThisTabs();
        });

    });
</script>